'''
@author: pnuzhnyi
'''

from django.http import HttpResponse
from events.repository import events_repository
from events.workers import run_event_simulation

def run_events(request):
    events_4_today = events_repository().get_events_scheduled_for_today()
    
    event_2_run = None
    
    for e in events_4_today:
        if e.status == 'pending': 
            event_2_run = e
            break
    
    if event_2_run is not None:
        run_event_simulation(event_2_run)
        return HttpResponse("running event: %s" % event_2_run.name)
    else:
        return HttpResponse("no events to run")
